﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using clEntidad;

namespace clBD
{
    public class BDLocal:BDBase
    {
        public BDLocal(OleDbConnection cn):base(cn){ }
        public BDLocal(OleDbConnection cn, OleDbTransaction trx) : base(cn, trx) { }
        public Local get(int id)
        {
            Local elem = null;
            String query = "SELECT nombre  from mlocal where id=" + id.ToString();
            OleDbDataReader dr = execDr(query);
            if (dr.Read())
            {
                elem = new Local();
                elem.id = id;
                elem.nombre = dr.GetString(0);
            }
            return elem;
        }
        public List<Local> getAll()
        {
            List<Local> elems = new List<Local>();
            String query = "select id,nombre from mlocal";
            OleDbDataReader dr = execDr(query);
            while (dr.Read())
            {
                Local elem = new Local();
                elem.id = dr.GetInt32(0);
                elem.nombre = dr.GetString(1);
                elems.Add(elem);
            }
            return elems;
        }
        public Local add(Local elem)
        {
            elem.id = getSeq("SEQ_LOC");
            String insert = "insert into mlocal(id,nombre) values (" + elem.id.ToString() + ",'" + elem.nombre + "')";
            execute(insert);
            return elem;
        }
        public void del(int id)
        {
            String delete = "delete from mlocal where id=" + id.ToString();
            execute(delete);
        }
        public void upd(Local elem)
        {
            String update = "update mlocal  set nombre='" + elem.nombre + "' where id=" + elem.id.ToString();
            execute(update);
        }

    }
}
